import axios from 'axios'
import router from '../router/index'
import nprogress from 'nprogress'
import 'nprogress/nprogress.css'
import store from '../store/index'
const instance = axios.create({
    baseURL: "http://117.131.101.11:8090",
    // baseURL: process.env.VUE_APP_BASE_API,
    timeout: 3000,
})
instance.interceptors.request.use((config) => {
    nprogress.start()
    // console.log(config)
    const token = store.state.user.userInfo.token
    if(token){
        config.headers['X-auth-token'] = token
    }
    return config
},err => {
    console.log(err)
})

instance.interceptors.response.use((res) => {
    nprogress.done()
    // console.log(router)
    // router.push({
    //     name: 'Resource'
    // })
    // console.log(window.location.href)
    return res.data
    
},err => {
    console.log(err.response)
    switch(err.response.status){
        case 401:
            router.push({
                path: '/login'
            })
        default:
    }
    // return err.response
})
// console.log(process.env.VUE_APP_BASE_API)
export default instance